﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
//using Web.Models;
using System.Collections.Specialized;

namespace Web.Controllers
{
    public class NoticeController : Controller
    {
        public ActionResult Index()
        {
            //ZebraCoreLib.Notice.Notice
            return Query();
        }

        public ActionResult Add()
        {
            return View();
        } 

        public ActionResult Query() 
        {
            string parameters = "sucode='";// + UserInfo.SuCode + "' ";

           
            NameValueCollection queryValues = new NameValueCollection();


            BuildQueryFieldValues(queryValues);

            if (queryValues.AllKeys.Contains("sgArea"))
                parameters += " and sgArea='" + queryValues["sgArea"] + "'";
            if (queryValues.AllKeys.Contains("sgStatus") && !string.IsNullOrEmpty(queryValues["sgStatus"]))
                parameters += " and seState=" + queryValues["sgStatus"] + "";
            if (queryValues.AllKeys.Contains("sgTime") && !string.IsNullOrEmpty(queryValues["sgTime"]))
            {
                int month = int.Parse(queryValues["sgTime"]);
                string beginTime = DateTime.Now.AddMonths(-month).ToString("yyyy/MM/dd") + " 00:00:00";
                parameters += " and optime>'" +beginTime + "'";
            }
            ViewData["queryValues"] = queryValues;
            ViewData["queryParameters"] = parameters;

            
            if(!string.IsNullOrEmpty(Request.QueryString["pageindex"]))
                ViewData["pageindex"] = Request.QueryString["pageindex"].ToString();

            return View("index"); 
        }


        protected void BuildQueryFieldValues(NameValueCollection queryValues)
        {
           
            System.Web.HttpRequest Request = System.Web.HttpContext.Current.Request;
          
            foreach (string key in Request.Form.Keys)
            {
 
                string value = Request.Form[key];
                if (value == "null") value = "";

                if (key != "Query")
                {
                    //parameters += string.Format(queryParameter, key, value);
                    queryValues.Add(key, value);
                
                }
            }


        }
    }
}
